﻿using System.ComponentModel;
using System.Web.UI;

namespace MyLib.Web.UI {
	/// <summary>
	/// 
	/// </summary>
	[ParseChildren(false)]
	[PersistChildren(true)]
	[DefaultProperty("Title")]
	[Designer(typeof(MyPanelContainerDesigner))]
	public class MyPanel : System.Web.UI.WebControls.WebControl {
		/// <summary>
		/// 
		/// </summary>
		[Bindable(true)]
		[Category("Accessibility")]
		public string Title { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[Category("Appearance")]
		[DefaultValue("")]
		public string TitleClass { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[Category("Appearance")]
		[DefaultValue("")]
		public string Title1Class { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[Category("Appearance")]
		[DefaultValue("")]
		public string ContentClass { get; set; }

		/// <summary>
		/// 
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderBeginTag(HtmlTextWriter writer) {
			AddAttributesToRender(writer);
			writer.RenderBeginTag(HtmlTextWriterTag.Div);
			if (!string.IsNullOrWhiteSpace(Title)) {
				if (!string.IsNullOrWhiteSpace(TitleClass)) {
					writer.AddAttribute(HtmlTextWriterAttribute.Class, TitleClass);
				}
				writer.RenderBeginTag(HtmlTextWriterTag.Div);
				if (!string.IsNullOrWhiteSpace(Title1Class)) {
					writer.AddAttribute(HtmlTextWriterAttribute.Class, Title1Class);
				}
				writer.RenderBeginTag(HtmlTextWriterTag.Div);
				writer.RenderEndTag();
				writer.WriteEncodedText(Title);
				writer.RenderEndTag();
			}
			if (!string.IsNullOrWhiteSpace(ContentClass)) {
				writer.AddAttribute(HtmlTextWriterAttribute.Class, ContentClass);
			}
			writer.RenderBeginTag(HtmlTextWriterTag.Div);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderEndTag(HtmlTextWriter writer) {
			writer.RenderEndTag();
			writer.RenderEndTag();
		}
	} // end of MyPanel.
}
